/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.SABM;

import entity.tx.Users;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.TX.LuckyDrawSBRemote;

/**
 *
 * @author TWD
 */
@ManagedBean
@SessionScoped
public class LuckyDrawMB2 {

    @EJB
    LuckyDrawSBRemote luckyDrawBean;
    private List<String> email;
    private List<Users> user;
    private String statusMessage;

    public LuckyDrawMB2() {
    }

    public void generateLuckyDrawWinners(ActionEvent event) {
        System.out.println("##################");
        Calendar myCal = Calendar.getInstance();
        int month;
        int year;
        month = myCal.get(Calendar.MONTH);
        year = myCal.get(Calendar.YEAR);
        if (month == 0) {
            month = 13;
        }
        List<String> email = luckyDrawBean.generateLuckyDrawWinners(month, year);
        if (email == null) {
            setEmail(null);
            setUser(null);
            statusMessage = "Lucky Draw Winners cant be generated due to empty transaction records";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Result: " + getStatusMessage(), ""));
        } else {
            setEmail(email);
            //return email;
            setUser(luckyDrawBean.generateUserInformation(email));
            statusMessage = "Lucky Draw Winners Generated";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Result: " + getStatusMessage(), ""));
        }
    }

    public List<String> getEmail() {
        return email;
    }

    public void setEmail(List<String> email) {
        this.email = email;
    }

    public List<Users> getUser() {
        return user;
    }

    public void setUser(List<Users> user) {
        this.user = user;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
}
